//
//  WelcomePage.m
//  BSS
//
//  Created by Juvi on 13-5-30.
//  Copyright (c) 2013年 juvid. All rights reserved.
//

#import "WelcomePage.h"
#import "DetectionSystemVersion.h"
@interface WelcomePage ()

@end

@implementation WelcomePage

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self BackButton];
    if (DEVICE_IS_IPHONE5) {
         arrImg=[[NSArray alloc]initWithObjects:@"welcome1.jpg",@"welcome2.jpg",@"welcome3.jpg",@"welcome4.jpg",@"welcome5.jpg",nil];
    }
    else{
        arrImg=[[NSArray alloc]initWithObjects:@"welcome41.jpg",@"welcome42.jpg",@"welcome43.jpg",@"welcome44.jpg",@"welcome45.jpg",nil];
    }
   
       // Do any additional setup after loading the view from its nib.
}
-(void)BackButton{
    if ([[DetectionSystemVersion alloc]Version]) {
        self.edgesForExtendedLayout=UIRectEdgeNone;
    }
    self.navigationItem.titleView=[DetectionSystemVersion SetBarTitle:@"百事搜"];
    [self.navigationItem setHidesBackButton:YES];
    UIButton *btnBack=[[DetectionSystemVersion alloc]BackButton];
    [btnBack addTarget:self action:@selector(BackReturn:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:btnBack];
    self.navigationItem.leftBarButtonItem=backItem;
    
}
#pragma mark 导航栏按钮事件
-(void)BackReturn:(id)sender{
//    [self.navigationController.view removeFromSuperview];
    [self HidePick:self.navigationController.view];
    [self.navigationController removeFromParentViewController];
}
-(void)viewDidAppear:(BOOL)animated{
     [self setScrollImage];
}
#pragma mark 动画
-(void)HidePick:(UIView *)vieBounced {
    [UIView animateWithDuration:0.3
                     animations:^(void) {
                         vieBounced.alpha = 0.0;
                         //                         vieBounced.frame = CGRectMake(0, self.view.frame.size.height, 104, (self.view.frame.size.height-117-8)/3);
                     } completion:^(BOOL finished) {
                         
                         [vieBounced removeFromSuperview];
                     }];
    
}
-(void)setScrollImage{
    self.scrWelc.contentSize = CGSizeMake(320*arrImg.count, self.scrWelc.frame.size.height);
    self.pages.numberOfPages = arrImg.count;
    for (int i = 0; i < arrImg.count; i++)
    {
        UIImageView *imgView;
        imgView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:[arrImg objectAtIndex:i]]];
        imgView.frame = CGRectMake(i*320, 0, 320, self.scrWelc.frame.size.height);
        [imgView setClipsToBounds:YES];
        [imgView setContentMode:UIViewContentModeScaleAspectFill];
        [self.scrWelc addSubview:imgView];
    }

}
#pragma mark -
#pragma mark UIScrollViewDelegate methods
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.pages.currentPage = (int)(self.scrWelc.contentOffset.x / self.scrWelc.frame.size.width);
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
